﻿<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Reference.Apps"
    xmlns:common="using:Reference.Apps.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Interactivity="using:Microsoft.Xaml.Interactivity" xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
    x:Name="pageRoot"
    x:Class="Reference.Apps.CodeView"
    mc:Ignorable="d">
	<Page.BottomAppBar>
		<CommandBar RequestedTheme="Light">
			<CommandBar.SecondaryCommands>
				<AppBarButton x:Uid="W8DecreaseFontSizeAppBarButton" Icon="FontDecrease" Label="AppBarButton">
					<Interactivity:Interaction.Behaviors>
						<Core:EventTriggerBehavior EventName="Click">
							<Core:InvokeCommandAction Command="{Binding DecrementFontSizeCommand, Mode=OneWay}"/>
						</Core:EventTriggerBehavior>
					</Interactivity:Interaction.Behaviors>
				</AppBarButton>
				<AppBarButton x:Uid="W8IncreaseFontSizeAppBarButton" Icon="FontIncrease" Label="AppBarButton">
					<Interactivity:Interaction.Behaviors>
						<Core:EventTriggerBehavior EventName="Click">
							<Core:InvokeCommandAction Command="{Binding IncrementFontSizeCommand, Mode=OneWay}"/>
						</Core:EventTriggerBehavior>
					</Interactivity:Interaction.Behaviors>
				</AppBarButton>
			</CommandBar.SecondaryCommands>
			<AppBarButton x:Uid="W8CopyCodeAppBarButton" Icon="Copy" Label="Copiar código" Command="{Binding CopyCodeToClipboardCommand, Mode=OneWay}"/>
		</CommandBar>
	</Page.BottomAppBar>
    <Page.DataContext>
        <Binding Mode="OneWay" Path="Main" Source="{StaticResource VMLocator}"/>
    </Page.DataContext>

    <Interactivity:Interaction.Behaviors>
        <Core:EventTriggerBehavior EventName="Loaded">
            <Core:InvokeCommandAction Command="{Binding GetCodeViewCommand, Mode=OneWay}"/>
        </Core:EventTriggerBehavior>
    </Interactivity:Interaction.Behaviors>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Background="{StaticResource ApplicationPageBackgroundBrush}" DataContext="{Binding Main.CodeViewSnippet, Source={StaticResource VMLocator}}">
    	<VisualStateManager.VisualStateGroups>
    		<VisualStateGroup x:Name="VisualStateGroup">
    			<VisualState x:Name="SmallWindow">
    				<Storyboard>
    					<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.Column)" Storyboard.TargetName="border">
    						<DiscreteObjectKeyFrame KeyTime="0">
    							<DiscreteObjectKeyFrame.Value>
    								<x:Int32>0</x:Int32>
    							</DiscreteObjectKeyFrame.Value>
    						</DiscreteObjectKeyFrame>
    					</ObjectAnimationUsingKeyFrames>
    					<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.Column)" Storyboard.TargetName="grid">
    						<DiscreteObjectKeyFrame KeyTime="0">
    							<DiscreteObjectKeyFrame.Value>
    								<x:Int32>0</x:Int32>
    							</DiscreteObjectKeyFrame.Value>
    						</DiscreteObjectKeyFrame>
    					</ObjectAnimationUsingKeyFrames>
    					<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.ColumnSpan)" Storyboard.TargetName="border">
    						<DiscreteObjectKeyFrame KeyTime="0">
    							<DiscreteObjectKeyFrame.Value>
    								<x:Int32>3</x:Int32>
    							</DiscreteObjectKeyFrame.Value>
    						</DiscreteObjectKeyFrame>
    					</ObjectAnimationUsingKeyFrames>
    				</Storyboard>
    			</VisualState>
    			<VisualState x:Name="Default"/>
    		</VisualStateGroup>
    	</VisualStateManager.VisualStateGroups>
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="160"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
				Style="{StaticResource MyButtonResource}"
				VerticalAlignment="Top"
				AutomationProperties.Name="Back"
				AutomationProperties.AutomationId="BackButton"
				AutomationProperties.ItemType="Navigation Button" Foreground="{StaticResource ApplicationContrastBackgroundBrush}" Background="White"/>
            <StackPanel Grid.Column="1" Margin="0,60,0,0">
                <TextBlock x:Name="pageTitle" Text="{Binding Title}" Style="{StaticResource HeaderTxtBlockStyle}" 
				IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,0,0"/>
                <TextBlock x:Name="pageSubtitle" Text="{Binding CodeGroupName}" Style="{StaticResource SubheaderTxtBlockStyle}" 
				IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="5,0,0,0"/>
            </StackPanel>

        </Grid>

        <Grid x:Name="grid" Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="420"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <StackPanel Grid.Column="1">
            	<TextBlock x:Uid="W8NotesTextBlock" TextWrapping="Wrap" Text="Notas" Style="{StaticResource SubtitleTextBlockStyle}" Foreground="{StaticResource ApplicationContrastBackgroundBrush}" FontWeight="Bold"/>
            	<TextBlock TextWrapping="Wrap" Text="{Binding Notes}" Style="{StaticResource BaseTextBlockStyle}" Foreground="{StaticResource ApplicationContrastBackgroundBrush}" Margin="0,0,10,0"/>
			</StackPanel>
			<Border x:Name="border" Grid.Column="2" Background="White">
            <StackPanel >
                <Border Background="{Binding Lang, Converter={StaticResource Lang2Brush}}">
                    <TextBlock Text="{Binding Lang, Converter={StaticResource Lang2Language}}" Style="{StaticResource SubheaderTextBlockStyle}" Margin="10,0,0,10" Foreground="White"  />
                </Border>
                <TextBlock x:Name="codeTextBlock" Text="{Binding Code}" HorizontalAlignment="Left" VerticalAlignment="Top"  FontFamily="Courier New" FontSize="{Binding Main.CodeFontSize, Source={StaticResource VMLocator}}" Margin="10" Foreground="{StaticResource ApplicationContrastBackgroundBrush}"/>
            </StackPanel>
			</Border>
        </Grid>
        <!-- Loading grid -->
        <Grid Grid.RowSpan="2" Background="{StaticResource ApplicationContrastBackgroundTransparetBrush}" Visibility="{Binding Main.IsBusy, Converter={StaticResource BoolToVisibilityConverter}}" DataContext="{Binding Source={StaticResource VMLocator}}">
            <Grid Background="{StaticResource ApplicationPageBackgroundBrush}" Height="200">
                <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Orientation="Horizontal">
                    <ProgressRing IsActive="{Binding Masin.IsBusy}" Height="41"  Width="41" />
                    <TextBlock VerticalAlignment="Center" Margin="10,0,0,0" Foreground="{StaticResource ApplicationContrastBackgroundBrush}" Style="{StaticResource SubheaderTextBlockStyle}">Cargando</TextBlock>
                </StackPanel>
            </Grid>
        </Grid>
    </Grid>
</Page>
